﻿<Window x:Class="SellAvi.Views.WindowPrepareMailing"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SellAvi.Views"
        xmlns:converters="clr-namespace:SellAvi.Views.Converters"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        Title="Подготовка списка рассылки" Height="400" Width="560"
        DataContext="{Binding Mailing, Source={StaticResource Locator}}"
    >
    <Window.Resources>
        <converters:InverseBooleanConverter x:Key="ibc" />
    </Window.Resources>
    <DockPanel>
        <GroupBox DockPanel.Dock="Top" Header="Подготовка списка получателей" Margin="2">
            <UniformGrid Columns="2">
                <StackPanel Orientation="Vertical" >
                    <DockPanel>
                        <Label Width="80" Content="Регион"/>
                        <local:ControlRegionCombobox Margin="2" ItemsSource="{Binding ServiceProxy.GetRegions}" SelectedRegion="{Binding ChoosenRegion, Mode=TwoWay}" SelectedCity="{Binding ChoosenCity,Mode=TwoWay}"/>
                    </DockPanel>
                    <DockPanel >
                        <Label  Width="80" Content="Категория"/>
                        <ComboBox  Margin="2" ItemsSource="{Binding ServiceProxy.GetCategories}" DisplayMemberPath="CategoryName" SelectedItem="{Binding ChoosenCategory}"/>
                    </DockPanel>
                    <DockPanel>
                        <Label  Width="80" Content="Тип тов-ра"/>
                        <ComboBox  Margin="2" ItemsSource="{Binding TFilteredParameters}" DisplayMemberPath="ParamName" SelectedItem="{Binding ChoosenParameter}"/>
                    </DockPanel>
                </StackPanel>
                <StackPanel Orientation="Vertical">
                    <DockPanel>
                        <Label  Width="30" Content=""/>
                        <Button DockPanel.Dock="Right" Command="{Binding GetRecepientsCommand}" Margin="2" IsEnabled="{Binding ParseInProgress,Converter={StaticResource ibc}, Mode=OneWay}">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="/SellAvi;component/Resources/manman.png" Width="14"/>
                                <StackPanel>
                                    <TextBlock Margin="5,0,5,0"><Run Text="Найти получателей по объявлениям" FontSize="10"/></TextBlock>
                                    <TextBlock Margin="5,0,5,0" TextAlignment="Center"><Run Text="{Binding ParseUrl}" FontSize="10"/></TextBlock>

                                </StackPanel>
                            </StackPanel>
                        </Button>
                    </DockPanel>

                    <!--<DockPanel>
                        <Label  Width="80" Content=""/>
                        <CheckBox IsChecked="True" Content="запрет повторной отправки" IsEnabled="False"/>
                    </DockPanel>-->

                </StackPanel>
            </UniformGrid>
        </GroupBox>



        <GroupBox DockPanel.Dock="Top" Margin="2" Header="Составление текста рассылки">
            <DockPanel LastChildFill="True" Height="80">
                <!--<AdornerDecorator></AdornerDecorator>-->
                <StackPanel DockPanel.Dock="Right" Width="120" Height="auto">
                    <Button Command="{Binding MessageSynthesisCommand}">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/SellAvi;component/Resources/type.png" Width="14"/>
                            <TextBlock Margin="5,0,5,0" TextWrapping="Wrap"><Run Text="Сгенерировать" ToolTip="Пересоздать текст отправки для нижеперечисленных объявлений"/></TextBlock>
                        </StackPanel>
                    </Button>
                    <DockPanel>
                        <TextBox DockPanel.Dock="Right" Width="40" Text="{Binding MailingSpeed}" FontSize="10" Margin="0" TextAlignment="Center"/>
                        <TextBlock Text="Задержка [cек.]" FontSize="10" TextAlignment="Left" Padding="5,0,5,0"></TextBlock>

                    </DockPanel>
                </StackPanel>
                <TextBox Text="{Binding MessageTemplate}" TextWrapping="Wrap"></TextBox>
            </DockPanel>
        </GroupBox>
        <DockPanel DockPanel.Dock="Bottom" Background="LightGray">
            <Button DockPanel.Dock="Right" Command="{Binding MarkMailCommand}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/time.png" Width="14"/>
                    <TextBlock Margin="5,0,5,0"><Run Text="Запланировать"/></TextBlock>
                </StackPanel>
            </Button>
            <Button DockPanel.Dock="Right" Command="{Binding RemoveDuplicatesCommand}" IsEnabled="False">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/equalizer.png" Width="14"/>
                    <TextBlock Margin="5,0,5,0"><Run Text="Генератор диалога"/></TextBlock>
                </StackPanel>
            </Button>
            <Button DockPanel.Dock="Right" Command="{Binding CleanSendToCollectionCommand}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/SellAvi;component/Resources/trash.png" Width="14"/>
                    <TextBlock Margin="5,0,5,0"><Run Text="Очистить все"/></TextBlock>
                </StackPanel>
            </Button>
            <!--<ProgressBar DockPanel.Dock="Left" Width="105" Margin="4"/>-->
            <DockPanel/>
        </DockPanel>
        <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding MailingCollection}" CanUserAddRows="False" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray">
            <!-- * Убираем границу при наводе фокуса на строку * -->
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                </Style>
            </DataGrid.CellStyle>

            <!-- * Запуск браузера при клике на строку * -->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <command:EventToCommand Command="{Binding RowClickCommand}"
                                CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=SelectedItem}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

            <DataGrid.Columns>
                <!--<DataGridHyperlinkColumn Header="#" Width ="auto" Binding="{Binding AdId}">
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <command:EventToCommand Command="{Binding EditProductCommand}"
                                CommandParameter="{Binding AdId}" />
                    </i:EventTrigger>
                </DataGridHyperlinkColumn>-->

                <DataGridTemplateColumn Header="#">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock DataContext="{Binding}">
                                <Hyperlink>
                                    <TextBlock Text="{Binding AdId}" />
                                </Hyperlink>
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <!--<DataGridTextColumn Width ="auto" Header="#" Binding="{Binding AdId, Mode=OneWay}" />-->
                <DataGridTextColumn Width ="150" Header="Объявление" Binding="{Binding LatinProductName, Mode=OneWay}" />
                <DataGridTextColumn Width="*" Header="Ответный текст сообщения" Binding="{Binding MessageText}" />
                <!--<DataGridTextColumn Width ="100" Header="Время" Binding="{Binding DatePosted}" />-->
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</Window>
